package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.SpuComment;
import com.example.vo.admin.AdminCommentVo;
import com.example.vo.comment.SpuCommentDash;
import com.example.vo.comment.SpuCommentVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SpuCommentMapper extends BaseMapper<SpuComment> {
    //查询商品评论列表
    List<SpuCommentVo> selectSpuCommentList(@Param("spuId") Long spuId,
                                            @Param("begin") Long begin,@Param("sortStr") String sortStr,@Param("type") Integer type);

    List<SpuCommentVo> selectReplyList(@Param("spuId") Long spuId,@Param("commentId") Long commentId);

    @Select("select count(*) from spu_comment_like where user_id = #{userId} and comment_id = #{commentId}")
    int getUserLikeCount(@Param("userId") Long userId,@Param("commentId") Long commentId);

    @Insert("insert into spu_comment_like(user_id, comment_id,spu_id) VALUES (#{userId},#{commentId},#{spuId})")
    void likeComment(@Param("userId") Long userId,@Param("commentId") Long commentId,@Param("spuId") Long spuId);

    @Delete("delete from spu_comment_like where user_id = #{userId} and comment_id = #{commentId}")
    void cancelLikeComment(@Param("userId") Long userId,@Param("commentId") Long commentId);

    @Select("select comment_id from spu_comment_like where user_id = #{userId} and spu_id = #{spuId}")
    List<Long> getLikeIds(@Param("userId") Long userId,@Param("spuId") Long spuId);

    SpuCommentDash getSpuCommentDash(@Param("spuId") Long spuId);

    List<AdminCommentVo> getAdminCommentList(@Param("begin") int begin,@Param("pageSize") Integer pageSize,@Param("keyword") String keyword);

    Long getAdminCommentCount(String keyword);
}
